package com.example.administrator.compileapp.drawer;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Parcelable;
import android.support.v4.util.Pair;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.android.databinding.library.baseAdapters.BR;
import com.example.administrator.compileapp.R;
import com.example.administrator.compileapp.bean.PersonInformationy;
import com.example.administrator.compileapp.databinding.ActivityPersonalInformationyBinding;
import com.example.administrator.compileapp.until.CommentRecyclerAdapter;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class PersonalInformationyActivity extends AppCompatActivity implements View.OnClickListener {
    private ActivityPersonalInformationyBinding binding;
    private CommentRecyclerAdapter<Object> adapter;
    private ArrayList<PersonInformationy> list;
    private final int REQUEST_CODE = 2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       binding = DataBindingUtil.setContentView(this,R.layout.activity_personal_informationy);
        init();
    }

    private void init() {
        binding.personInfoBack.setOnClickListener(this);
        binding.personInfoB.setOnClickListener(this);
        binding.personInfoTitle.setText(getIntent().getStringExtra("logn"));
        list = new ArrayList<>();
        PersonInformationy informationy= new PersonInformationy("拜永","男","24","1-1","1443881887@qq.com","15595442433","好好写论文");
        list.add(informationy);
        HashMap<Class<?>,Pair<Integer,Integer>> map = new HashMap<>();
        map.put(null,Pair.create(R.layout.informationy, BR.personInformationy));
        adapter = new CommentRecyclerAdapter<>(this,new ArrayList<>(),map);
        adapter.add(informationy);
        binding.recycler.setAdapter(adapter);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode==REQUEST_CODE){
            Bundle bundle = data.getBundleExtra("bundle");
            List<PersonInformationy> list1 = (List<PersonInformationy>) bundle.getSerializable("list");
            list.clear();
            list.add(list1.get(0));
            adapter.add(list1.get(0));
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.person_info_back:
              //  finish();
                break;
            case R.id.person_info_b:
                Intent intent = new Intent(this,EditorActivity.class);
                Bundle bundle = new Bundle();
                bundle.putSerializable("list",list);
                intent.putExtra("bundle",bundle);
                startActivityForResult(intent,REQUEST_CODE);
                overridePendingTransition(R.anim.activity_come,0);
                adapter.remove(0);
                break;
        }
    }
}
